package com.joyoung.sweep.base;

import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.transition.Fade;

import androidx.annotation.ColorRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import com.blankj.utilcode.util.BarUtils;
import com.joyoung.sweep.R;


/**
 * @author: ThinkPad
 * date: 2021/4/12
 * desc: 基础
 */
public class BaseActivity extends AppCompatActivity {
    public final String TAG = getClass().getSimpleName();
    public Context mContext;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BarUtils.setStatusBarColor(this, getColors(R.color.white));
        BarUtils.setStatusBarLightMode(this,true);
        getWindow().setEnterTransition(new Fade());
        getWindow().setExitTransition(new Fade());
        mContext = this;
    }

    protected void openActivity(Class<?> pClass) {
        Intent intent = new Intent(this, pClass);
        startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
    }

    protected void openAct(Class<?> pClass) {
        Intent intent = new Intent(this, pClass);
        startActivity(intent);
        overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
    }


    //打开
    public void openActivity(Class<?> pClass, Bundle pBundle) {
        Intent intent = new Intent(this, pClass);
        if (pBundle != null) {
            intent.putExtras(pBundle);
        }
        startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
    }

    public void openActivity(Intent intent) {
        startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
    }

    public void openActivityForResult(Class<?> pClass, int code) {
        //动画
        Intent intent = new Intent(this, pClass);
        startActivityForResult(intent, code, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
    }

    public void openActivityForResult(Intent intent, int code) {
        //动画
        startActivityForResult(intent, code, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
    }

    public int getColors(@ColorRes int res) {
        return ContextCompat.getColor(this, res);
    }
}
